﻿using Catchbase.TestTools;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Catchbase.Service.API.UTest
{
    [TestClass]
    public class CatchbaseUriBuilderTest
    {
        private CatchbaseUriBuilder _subject;

        [TestInitialize]
        public void InitializeTest()
        {
            _subject = new CatchbaseUriBuilder("http://localhost:666/");
        }

        [TestMethod]
        public void Build_MustReturnUriWithScheme()
        {
            _subject.Build<TestObject>().Scheme.MustEqual("http");
        }

        [TestMethod]
        public void Build_MustReturnUriWithHost()
        {
            _subject.Build<TestObject>().Host.MustEqual("localhost");
        }

        [TestMethod]
        public void Build_MustReturnUriWithPort()
        {
            _subject.Build<TestObject>().Port.MustEqual(666);
        }

        [TestMethod]
        public void Build_MustReturnTAsPath()
        {
            _subject.Build<TestObject>().AbsoluteUri.MustEqual("http://localhost:666/testobject");
        }

        [TestMethod]
        public void Build_MustReturnComplexUri()
        {
            _subject = new CatchbaseUriBuilder("http://catchbase.cloudapp.net");
            _subject.Build<TestObject>().AbsoluteUri.MustEqual("http://catchbase.cloudapp.net/testobject");
        }

        [TestMethod]
        public void Build_MustReturnComplexUri_AlsoWhenSlashIsTrailing()
        {
            _subject = new CatchbaseUriBuilder("http://catchbase.cloudapp.net/");
            _subject.Build<TestObject>().AbsoluteUri.MustEqual("http://catchbase.cloudapp.net/testobject");
        }

        [TestMethod]
        public void Build_MustReturnTestUri()
        {
            _subject = new CatchbaseUriBuilder("http://8ebedd4a55774ba0922b26939cac2e4f.cloudapp.net");
            _subject.Build<TestObject>().AbsoluteUri.MustEqual("http://8ebedd4a55774ba0922b26939cac2e4f.cloudapp.net/testobject");
        }

        [TestMethod]
        public void Build_MustInlcudeIdInPath()
        {
            _subject.Build<TestObject>("someid").AbsoluteUri.MustEqual("http://localhost:666/testobject/someid");
        }
    }
}